package com.tddx.activiti.base;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

import com.tddx.activiti.business.sys.entity.systuser.SysTuserEntity;
import com.tddx.activiti.business.sys.util.SysTuserUtil;
import com.tddx.activiti.common.IdGenerator;

@MappedSuperclass
public abstract class BaseEntity implements Serializable {
	
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name="ID", length=30, columnDefinition="number")
	private Long id;
	
	@Column(name="VC_SERVER", length=10, updatable=false, columnDefinition="VARCHAR2(10)")
	private String vcServer = IdGenerator.serverId;
	
	@Column(name="DT_CREATE", updatable=false, columnDefinition="DATE")
	private Date dtCreate = new Date();
	
	@Column(name="DT_UPDATE", columnDefinition="DATE")
	private Date dtUpdate = new Date();
	
	@Column(name="VC_ORGID", length=50, columnDefinition="VARCHAR2(50)")
	private String vcOrgid;
	
	@Column(name="VC_UPDATE", length=50, columnDefinition="VARCHAR2(50)")
	private String vcUpdate;
	
	@Column(name="VC_CREATE", length=50, updatable = false, columnDefinition="VARCHAR2(50)")
	private String vcCreate;
	
	@Column(name="VC_DEL", length=1, columnDefinition="VARCHAR2(1)")
	private String vcDel = NO_DEL;

	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}

	public Date getDtCreate() {
		return dtCreate;
	}

	public void setDtCreate(Date dtCreate) {
		this.dtCreate = dtCreate;
	}

	public Date getDtUpdate() {
		return dtUpdate;
	}

	public void setDtUpdate(Date dtUpdate) {
		this.dtUpdate = dtUpdate;
	}

	public String getVcOrgid() {
		return vcOrgid;
	}

	public void setVcOrgid(String vcOrgid) {
		this.vcOrgid = vcOrgid;
	}

	public String getVcDel() {
		return vcDel;
	}

	public void setVcDel(String vcDel) {
		this.vcDel = vcDel;
	}
	
	public String getVcUpdate() {
		return vcUpdate;
	}

	public void setVcUpdate(String vcUpdate) {
		this.vcUpdate = vcUpdate;
	}

	public String getVcCreate() {
		return vcCreate;
	}

	public void setVcCreate(String vcCreate) {
		this.vcCreate = vcCreate;
	}

	public String getVcServer() {
		return vcServer;
	}

	public void setVcServer(String vcServer) {
		this.vcServer = vcServer;
	}

	/**
	 * 插入之前执行方法，需要手动调用
	 */
	@PrePersist
	public void preInsert(){
		SysTuserEntity user = SysTuserUtil.getCurrentUser();
		if(user!=null&&user.getId()!=null){
			this.vcCreate = user.getVcUsername();
			this.vcUpdate = user.getVcUsername();
		}else{
			this.vcCreate = "admin";
			this.vcUpdate = "admin";
		}
	}
	
	/**
	 * 更新之前执行方法，需要手动调用
	 */
	@PreUpdate
	public void preUpdate(){
		SysTuserEntity user = SysTuserUtil.getCurrentUser();
		if(user!=null&&user.getId()!=null){
			this.vcUpdate = user.getVcUsername();
		}
	}
	
	public final static String NO_DEL = "0";
	public final static String IS_DEL = "1";
	protected final static String MENU_SEE="1";//菜单可见
	protected final static String MENU_HIDDEN="0";//菜单不可见
	
}